'use strict';
/**
 * model
 */
export default class extends think.model.base {
    async addWork(obj) {
        let Work = await this.add(obj);
        return Work;
    }

    async getWork(obj) {
        let sqlStr;
        let room;
        if (obj.order.active) {
            room =await this.query('select @rownum:=@rownum+1 AS orderPoll,id,active,text,imgUrl,workName,userName from `weal_active`,(SELECT @rownum:=0) r ORDER BY active desc')
        } else {
             room=await this.query('select * from (select @rownum:=@rownum+1 AS orderPoll,id,active,text,imgUrl,workName,userName from `weal_active`,(SELECT @rownum:=0) r ORDER BY active desc)b order by id asc')
        }
        return room;
    }


    async findWork(obj) {
        let room = await this.where(obj.where).order(obj.order).find();
        return room;
    }

    async pollAdd(obj) {
        console.log(obj.where)
        let room = await this.where(obj.where).increment('active', 1);
        return room;
    }
}
